package com.qf.zxq.code.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.group.common.base.utils.CommonBeanutils;
import com.qf.zxq.code.common.qo.CommodityQo;
import com.qf.zxq.code.common.utils.ConversionTool;
import com.qf.zxq.code.common.vo.CommodityVo;
import com.qf.zxq.code.entity.Commodity;
import com.qf.zxq.code.mapper.CommodityMapper;
import com.qf.zxq.code.service.CommodityService;
import com.sun.org.apache.xerces.internal.impl.xs.models.XSAllCM;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;

@Service
public class CommodityServiceImpl implements CommodityService {

    @Resource
    private CommodityMapper commodityMapper;

    @Override
    public IPage<CommodityVo> searchAll(Integer page, Integer size, CommodityQo commodityQo) {
        // 穿件分页条件构造器
        Page<Commodity> commodityPage = new Page<>(page, size);

        // 创建条件查询构造器
        QueryWrapper<Commodity> qw = new QueryWrapper<>();
        // 通过自定义的方法使用反射添加参数
        IPage<Commodity> commodityIPage = commodityMapper.selectByCommodityQo(commodityPage, ConversionTool.addConditions(qw, commodityQo));

        // 将数据转换为vo对象，直接返回结果
        return CommonBeanutils.convertPageInfo(commodityIPage, new Page<>(), CommodityVo::new);
    }


}
